#pragma once

#include "condition.h"
#include "vector2.h"
#include "world.h"
#include "agent.h"


namespace BAA
{

	class Condition_IsNear:public Condition
	{
	public:


		Condition_IsNear(const string name, Vector2 * range):Condition(name)
		{
			mRange.x = range->x;
			mRange.y = range->y;
		}

		inline void setParameters(const Agent * a, Vector3 pos, float nearDistance)
		{
			mAgent = a;
			mPOSITION = pos;
			mNearDistance = nearDistance;
			mDirty = false;
			
		}

		inline float isTrue()
		{
			if(mDirty)
			{
				return mResult;
			}
			else
			{
				mResult = world->DistanceBetween(mAgent, &mPOSITION);
				if(mResult < mNearDistance)
				{					
					mResult = 1; // true
				}
				else
				{
					mResult = -1;// false
				}

				mDirty = true;
			}
			
		}


		~Condition()
		{

		}

	protected:
		// any members
		World *		world;
		Agent *		mAgent;
		Vector3		mPOSITION;
		float		mNearDistance;

		Vector2		mRange;
		
		bool		mDirty = false;
		float		mResult = -1;
	};// end class
}// end namespace
